package com.cy.springcloudalibaba.parsers;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 自定义请求来源解析类，sentinel系统规则
 * @ClassName: CustomRequestOriginParser
 * @Author: chenyu
 * @Date: 2025/1/17 17:02
 */
//@Component
public class CustomRequestOriginParser implements RequestOriginParser {
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        String origin = httpServletRequest.getParameter("origin");

        if (StringUtils.isBlank(origin)) {
            throw new IllegalArgumentException("origin参数未指定");
        }
        return origin;
    }
}
